<template>
<div style="width: 100%;">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="姓名"
          hasFeedback >
          <a-input placeholder="请输入姓名" v-decorator="['name', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="关键词"
          hasFeedback >
          <a-input placeholder="请输入关键词" v-decorator="['keyWord', {}]" />
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="附件"
          hasFeedback >
          <div class="clearfix">
            <a-upload
              :fileList="fileList"
              @preview="handlePreview"
            >
            </a-upload>

          </div>
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="打卡时间"
          hasFeedback >
          <a-date-picker showTime format="YYYY-MM-DD HH:mm:ss" v-decorator="[ 'punchTime', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="sex">
          <a-select v-decorator="['sex', {}]" placeholder="请选择性别">
            <a-select-option value="">请选择性别</a-select-option>
            <a-select-option value="1">男性</a-select-option>
            <a-select-option value="2">女性</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="年龄"
          hasFeedback >
          <a-input placeholder="请输入年龄" v-decorator="['age', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="生日"
          hasFeedback >
          <a-date-picker v-decorator="[ 'birthday', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="邮箱"
          hasFeedback >
          <a-input placeholder="请输入邮箱" v-decorator="['email', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="个人简介"
          hasFeedback >
          <a-input placeholder="请输入个人简介" v-decorator="['content', {}]" />
        </a-form-item>

      </a-form>
    </a-spin>
</div>
</template>

<script>
  import { getAction } from '@lone/lone-vue/src/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "JeecgDemoFlow",
    props: {
      idManage: {
        type: String,
        default: '',
        required: false
      },

    },
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        disableSubmit:false,
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        fileList: [],
        uploading: false,
        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        },
        url: {
          add: "/test/jeecgDemo/add",
          edit: "/test/jeecgDemo/edit",
        },
      }
    },
    created () {
      this.initData();
    },
    methods: {
      initFileList(){
        this.fileList = [];
        this.uploading = false;
        if(this.model.id){
          var params = {
            buiId:this.model.id
          };
          getAction("/mongo/mongoDocs/queryByBui",params).then((res)=>{
            res.forEach((item,index)=>{
              console.log(':' + item.id + index);
              var properties = {
                uid: item.id,
                name :item.fileName,
                status: 'done', // 状态有：uploading done error removed
                response: '{"status": "success"}' // 服务端响应内容
              };
              var file = Object.assign(properties);

              this.fileList = [...this.fileList, file];
            })

          });
        }

      },
      handlePreview(file) {
        var params = {
          id:file.uid
        };
        //downFile("/mongo/mongoDocs/viewFile",params);

        let paramsStr = encodeURI(JSON.stringify(params));
        console.log('paramsStr: ' + paramsStr)
        let url = `${window._CONFIG['domianURL']}/mongo/mongoDocs/viewFile?paramsStr=${paramsStr}`+ `&id=` + file.uid;
        window.location.href = url;
      },

      initData (record) {
        this.form.resetFields();

        if (record) {
          this.idManage = record.idManage;
        }


        var params = {
          id:this.idManage
        };
        getAction("/test/jeecgDemo/redisDemo/"+this.idManage,params).then((res)=>{
          if(res) {
            this.model = res;
            this.$nextTick(() => {
              this.form.setFieldsValue(pick(this.model,'name','keyWord','sex','age','email','content'))
              //时间格式化
              this.form.setFieldsValue({punchTime:this.model.punchTime?moment(this.model.punchTime,'YYYY-MM-DD HH:mm:ss'):null})
              this.form.setFieldsValue({birthday:this.model.birthday?moment(this.model.birthday):null})
            });
            this.visible = true;

            this.initFileList();
          }else{
            this.$message.warning('数据未找到');
          }
        });

        //this.model = Object.assign({}, record);

      },
      close () {
        this.$emit('close');
        this.visible = false;
        this.disableSubmit = false;
      },

      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style scoped>

</style>